﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows;
using System.Windows.Markup;
using System.Windows.Resources;

namespace SDF.Controls
{
    [ContentProperty("Document")]
    public class SmartDocumentViewer: Control
    {
        #region Constructor

        public SmartDocumentViewer()
        {
            this.Template = DefaultTemplate;
        }

        #endregion

        #region Dependency Properties

        public static readonly DependencyProperty DocumentProperty = DependencyProperty.Register(
            "Document",
            typeof(SmartDocument),
            typeof(SmartDocumentViewer),
            new PropertyMetadata(null));

        #endregion

        #region Properties

        public SmartDocument Document
        {
            get { return (SmartDocument)GetValue(DocumentProperty); }
            set { SetValue(DocumentProperty, value); }
        }

        #endregion

        #region DefaultTemplate Property

        public static ControlTemplate DefaultTemplate
        {
            get
            {
                if (_DefaultTemplate == null)
                {
                    // Navigate to xaml page
                    Uri uri = new Uri("SDF;component/Resources/SmartDocumentViewerTemplate.xaml", UriKind.Relative);
                    StreamResourceInfo info = Application.GetResourceStream(uri);
                    XamlReader reader = new XamlReader();
                    _DefaultTemplate = (ControlTemplate)reader.LoadAsync(info.Stream);
                }
                return _DefaultTemplate;
            }
        }
        private static ControlTemplate _DefaultTemplate;

        #endregion

    }
}
